﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.workPlan
{
    public partial class WorkPlanCheck : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                    int user_depid = 0;
                    if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_depid"].ToString()))
                    {
                        user_depid = Convert.ToInt32(ds.Tables[0].Rows[0]["user_depid"].ToString());
                    }
                    if (roles_id == 1024)
                    {
                        //班长

                        this.btn_yes.Visible = true;
                        this.btn_no.Visible = true;
                    }
                    if (roles_id == 1025)
                    {
                        //绩效专责

                        this.btn_yes.Visible = true;
                        this.btn_no.Visible = true;


                    }
                    if (roles_id == 1026)
                    {
                        //部门经理
                        
                        this.btn_yes.Visible = false;
                        this.btn_no.Visible = false;
                      
                    }
                }
            }
        }

       

        protected void btn_yes_Click(object sender, EventArgs e)
        {
            Maticsoft.BLL.workplan wm = new Maticsoft.BLL.workplan();
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                int user_depid = 0;
                if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_depid"].ToString()))
                {
                    user_depid = Convert.ToInt32(ds.Tables[0].Rows[0]["user_depid"].ToString());
                }

                if (roles_id == 1024)
                {
                    //班长
                    if (!string.IsNullOrEmpty(Request["workplan_id"]))
                    {
                        int workplan_id = int.Parse(Request["workplan_id"]);

                        Maticsoft.Model.workplan w = wm.GetModel(workplan_id);

                        w.check_step = "班长评价";

                        CheckWorkPlan(wm, user_id, w);
                    }
                }
                if (roles_id == 1025)
                {
                    //绩效专责
                    if (!string.IsNullOrEmpty(Request["workplan_id"]))
                    {
                        int workplan_id = int.Parse(Request["workplan_id"]);

                        Maticsoft.Model.workplan w = wm.GetModel(workplan_id);

                        w.check_step = "绩效专责评价";

                        CheckWorkPlan(wm, user_id, w);
                    }
                   
                }
                //if (roles_id == 1026)
                //{
                //    //部门经理
                //    if (!string.IsNullOrEmpty(Request["workplan_id"]))
                //    {
                //        int workplan_id = int.Parse(Request["workplan_id"]);

                //        Maticsoft.Model.workplan w = wm.GetModel(workplan_id);

                //        w.check_step = "审核完成";

                //        CheckWorkPlan(wm, user_id, w);
                //    }

                //}

            }
        }

        private void CheckWorkPlan(Maticsoft.BLL.workplan wm, int user_id, Maticsoft.Model.workplan w)
        {
            if (wm.Update(w))
            {
                Maticsoft.BLL.workplan_evaluate wem = new Maticsoft.BLL.workplan_evaluate();
                Maticsoft.Model.workplan_evaluate we = new Maticsoft.Model.workplan_evaluate();

                we.eva_time = DateTime.Now;
                we.eva_uid = user_id;
                we.workplan_id = w.workplan_id;
                
                
                if (w.check_step == "班长评价")
                {
                    //班长
                    //we.eva_content += "-班长评价";
                    we.eva_userRole = "班长";
                }

                if (w.check_step == "绩效专责评价")
                {
                    //绩效专责
                    //we.eva_content += "-绩效专责评价";
                    we.eva_userRole = "绩效专责";
                }
                if (w.check_step == "审核完成")
                {
                    //部门经理
                    //we.eva_content += "-部门经理评价";
                    we.eva_userRole = "部门经理";
                }

                //if (wem.Add(we) > 0)
                //{
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this.Page, "提交成功！", "ListWorkPlan.aspx");
                //}


            }
        }

        //未通过
        protected void btn_no_Click(object sender, EventArgs e)
        {
            Maticsoft.BLL.workplan wm = new Maticsoft.BLL.workplan();
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                int user_depid = 0;
                if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_depid"].ToString()))
                {
                    user_depid = Convert.ToInt32(ds.Tables[0].Rows[0]["user_depid"].ToString());
                }

                if (roles_id == 1024)
                {
                    //班长
                    if (!string.IsNullOrEmpty(Request["workplan_id"]))
                    {
                        int workplan_id = int.Parse(Request["workplan_id"]);

                        Maticsoft.Model.workplan w = wm.GetModel(workplan_id);

                        w.check_step = "班长审核";

                        CheckWorkPlan(wm, user_id, w);
                    }
                }
                if (roles_id == 1025)
                {
                    //绩效专责
                    if (!string.IsNullOrEmpty(Request["workplan_id"]))
                    {
                        int workplan_id = int.Parse(Request["workplan_id"]);

                        Maticsoft.Model.workplan w = wm.GetModel(workplan_id);

                        w.check_step = "绩效专责审核";

                        CheckWorkPlan(wm, user_id, w);
                    }

                }
                //if (roles_id == 1026)
                //{
                //    //部门经理
                //    if (!string.IsNullOrEmpty(Request["workplan_id"]))
                //    {
                //        int workplan_id = int.Parse(Request["workplan_id"]);

                //        Maticsoft.Model.workplan w = wm.GetModel(workplan_id);

                //        w.check_step = "绩效专责审核";

                //        CheckWorkPlan(wm, user_id, w);
                //    }

                //}

            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }

      
    }
}